/
ITypedHttpClientFactory`1.xml
166 lines (161 loc) · 9.9 KB
/
ITypedHttpClientFactory`1.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<Type Name="ITypedHttpClientFactory<TClient>" FullName="Microsoft.Extensions.Http.ITypedHttpClientFactory<TClient>">
<TypeSignature Language="C#" Value="public interface ITypedHttpClientFactory<TClient>" />
<TypeSignature Language="ILAsm" Value=".class public interface auto ansi abstract ITypedHttpClientFactory`1<TClient>" FrameworkAlternate="dotnet-plat-ext-2.1;dotnet-plat-ext-2.2;dotnet-plat-ext-3.0;dotnet-plat-ext-3.1;dotnet-plat-ext-5.0" />
<TypeSignature Language="DocId" Value="T:Microsoft.Extensions.Http.ITypedHttpClientFactory`1" />
<TypeSignature Language="VB.NET" Value="Public Interface ITypedHttpClientFactory(Of TClient)" />
<TypeSignature Language="F#" Value="type ITypedHttpClientFactory<'Client> = interface" />
<TypeSignature Language="C++ CLI" Value="generic <typename TClient>
public interface class ITypedHttpClientFactory" />
<TypeSignature Language="ILAsm" Value=".class public interface auto ansi abstract beforefieldinit ITypedHttpClientFactory`1<TClient>" FrameworkAlternate="net-6.0;net-7.0;net-8.0;net-9.0;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0" />
<AssemblyInfo>
<AssemblyName>Microsoft.Extensions.Http</AssemblyName>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
<AssemblyVersion>2.2.0.0</AssemblyVersion>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>3.1.0.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<TypeParameters>
<TypeParameter Name="TClient">
<Attributes>
<Attribute FrameworkAlternate="net-6.0;net-7.0;net-8.0;net-9.0">
<AttributeName Language="C#">[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)]</AttributeName>
<AttributeName Language="F#">[<System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(2)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Interfaces />
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.NullableContext(1)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.NullableContext(1)>]</AttributeName>
</Attribute>
</Attributes>
<Docs>
<typeparam name="TClient">The type of typed client to create.</typeparam>
<summary>
A factory abstraction for a component that can create typed client instances with custom
configuration for a given logical name.
</summary>
<remarks>
<para>
The <see cref="T:Microsoft.Extensions.Http.ITypedHttpClientFactory`1" /> is infrastructure that supports the
<see cref="M:Microsoft.Extensions.DependencyInjection.HttpClientFactoryServiceCollectionExtensions.AddHttpClient``1(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.String)" /> and
<see cref="M:Microsoft.Extensions.DependencyInjection.HttpClientBuilderExtensions.AddTypedClient``1(Microsoft.Extensions.DependencyInjection.IHttpClientBuilder)" /> functionality. This type
should rarely be used directly in application code, use <see cref="M:System.IServiceProvider.GetService(System.Type)" /> instead
to retrieve typed clients.
</para>
<para>
A default <see cref="T:Microsoft.Extensions.Http.ITypedHttpClientFactory`1" /> can be registered in an <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" />
by calling <see cref="M:Microsoft.Extensions.DependencyInjection.HttpClientFactoryServiceCollectionExtensions.AddHttpClient(Microsoft.Extensions.DependencyInjection.IServiceCollection)" />.
The default <see cref="T:Microsoft.Extensions.Http.ITypedHttpClientFactory`1" /> will be registered in the service collection as a singleton
open-generic service.
</para>
<para>
The default <see cref="T:Microsoft.Extensions.Http.ITypedHttpClientFactory`1" /> uses type activation to create typed client instances. Typed
client types are not retrieved directly from the <see cref="T:System.IServiceProvider" />. See
<see cref="M:Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(System.IServiceProvider,System.Type,System.Object[])" /> for details.
</para>
</remarks>
<example>
This sample shows the basic pattern for defining a typed client class.
<code language="csharp">
class ExampleClient
{
private readonly HttpClient _httpClient;
private readonly ILogger _logger;
// typed clients can use constructor injection to access additional services
public ExampleClient(HttpClient httpClient, ILogger<ExampleClient> logger)
{
_httpClient = httpClient;
_logger = logger;
}
// typed clients can expose the HttpClient for application code to call directly
public HttpClient HttpClient => _httpClient;
// typed clients can also define methods that abstract usage of the HttpClient
public async Task SendHelloRequest()
{
var response = await _httpClient.GetAsync("/helloworld");
response.EnsureSuccessStatusCode();
}
}
</code></example>
<example>
This sample shows how to consume a typed client from an ASP.NET Core middleware.
<code language="csharp">
// in Startup.cs
public void Configure(IApplicationBuilder app, ExampleClient exampleClient)
{
app.Run(async (context) =>
{
var response = await _exampleClient.GetAsync("/helloworld");
await context.Response.WriteAsync("Remote server said: ");
await response.Content.CopyToAsync(context.Response.Body);
});
}
</code></example>
<example>
This sample shows how to consume a typed client from an ASP.NET Core MVC Controller.
<code language="csharp">
// in Controllers/HomeController.cs
public class HomeController : ControllerBase(IApplicationBuilder app, ExampleClient exampleClient)
{
private readonly ExampleClient _exampleClient;
public HomeController(ExampleClient exampleClient)
{
_exampleClient = exampleClient;
}
public async Task<IActionResult> Index()
{
var response = await _exampleClient.GetAsync("/helloworld");
var text = await response.Content.ReadAsStringAsync();
return Content("Remote server said: " + text, "text/plain");
};
}
</code></example>
</Docs>
<Members>
<Member MemberName="CreateClient">
<MemberSignature Language="C#" Value="public TClient CreateClient (System.Net.Http.HttpClient httpClient);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance !TClient CreateClient(class System.Net.Http.HttpClient httpClient) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.Extensions.Http.ITypedHttpClientFactory`1.CreateClient(System.Net.Http.HttpClient)" />
<MemberSignature Language="VB.NET" Value="Public Function CreateClient (httpClient As HttpClient) As TClient" />
<MemberSignature Language="F#" Value="abstract member CreateClient : System.Net.Http.HttpClient -> 'Client" Usage="iTypedHttpClientFactory.CreateClient httpClient" />
<MemberSignature Language="C++ CLI" Value="public:
 TClient CreateClient(System::Net::Http::HttpClient ^ httpClient);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.Extensions.Http</AssemblyName>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
<AssemblyVersion>2.2.0.0</AssemblyVersion>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>3.1.0.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>TClient</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="httpClient" Type="System.Net.Http.HttpClient" />
</Parameters>
<Docs>
<param name="httpClient">
An <see cref="T:System.Net.Http.HttpClient" /> created by the <see cref="T:System.Net.Http.IHttpClientFactory" /> for the named client
associated with <typeparamref name="TClient" />.
</param>
<summary>Creates a typed client given an associated <see cref="T:System.Net.Http.HttpClient" />.</summary>
<returns>An instance of <typeparamref name="TClient" />.</returns>
<remarks>To be added.</remarks>
</Docs>
</Member>
</Members>
</Type>